package com.hc.conferencecheck.controller;

import com.hc.conferencecheck.entity.Conference;
import com.hc.conferencecheck.entity.ResultMsg;
import com.hc.conferencecheck.entity.ResultStatusCode;
import com.hc.conferencecheck.service.ConferenceService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/conferenceController")
public class ConferenceController {
    @Resource
    private ConferenceService conferenceServiceImpl;

    /**
     * 修改会议对象
     */
    @RequestMapping("/editConference")
    public ResultMsg editConference(@RequestBody Conference conference) {
        ResultMsg resultMsg = conferenceServiceImpl.editConference(conference);
        return resultMsg;
    }

    /**
     * 删除会议对象
     */
    @RequestMapping("/deleteConferenceByPrimaryKey")
    public ResultMsg deleteConferenceByPrimaryKey(@RequestBody Map<String, Object> params) {
        Object conferenceIdObj = params.get("conferenceId");
        if (conferenceIdObj == null) {
            return new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.EORROR.getMsg(), "参数不可为空");
        }
        int conferenceId = Integer.parseInt(conferenceIdObj.toString());
        ResultMsg resultMsg = conferenceServiceImpl.deleteConferenceByPrimaryKey(conferenceId);
        return resultMsg;
    }

    /**
     * 添加会议对象
     */
    @RequestMapping("/createConference")
    public ResultMsg createConference(@RequestBody Conference conference) {
        ResultMsg resultMsg = conferenceServiceImpl.createConference(conference);
        return resultMsg;
    }

    /**
     * 申请报名会议接口
     */
    @RequestMapping("/applyConference")
    public ResultMsg applyConference(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = conferenceServiceImpl.applyConference(params);
        return resultMsg;
    }

    /**
     * 根据主键查询指定的会议对象
     *
     * @return
     */
    @RequestMapping("/selectConferenceByPrimaryKey")
    public ResultMsg selectConferenceByPrimaryKey(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = conferenceServiceImpl.selectConferenceByPrimaryKey(params);
        return resultMsg;
    }


    /**
     * 查询所有的会议对象
     */
    @RequestMapping("/selectAllConferences")
    public ResultMsg selectAllConferences(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = conferenceServiceImpl.selectAllConferences(params);
        return resultMsg;
    }

}
